package com.fzkj.bio.part4;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * 服务端socket处理线程池
 */
public class ServerSocketPoolHandler {

    private ExecutorService executorService;

    /**
 *     public ThreadPoolExecutor(int corePoolSize, // 核心数
 *                               int maximumPoolSize, // 最大线程数量
 *                               long keepAliveTime,
 *                               TimeUnit unit,
 *                               BlockingQueue<Runnable> workQueue)
     * @param maxThread
     * @param queueSize
     */
    public ServerSocketPoolHandler(int maxThread, int queueSize){
        executorService = new ThreadPoolExecutor(2, maxThread, 120, TimeUnit.SECONDS,
                new ArrayBlockingQueue<Runnable>(queueSize));
    }

    /**
     * 交由线程池
     * @param target
     */
    public void execute(Runnable target) {
        executorService.execute(target);
    }

}
